package com.example.travelservlet.collection.controller;

import com.example.travelservlet.collection.repository.CollectionRepository;
import com.example.travelservlet.collection.service.CollectionService;
import com.example.travelservlet.entity.Collection;
import com.example.travelservlet.entity.User;
import com.example.travelservlet.user.domain.Result;
import com.example.travelservlet.user.service.UserService;
import com.example.travelservlet.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.UUID;

/**
 * @author hxy
 * @date 2022/11/8 9:17
 */
@RestController
@RequestMapping("/collection")
public class CollectionController {
    @Autowired
    private CollectionService collectionService;
    @Autowired
    private UserService userService;

    @GetMapping("/createCollection/{loginName}")
    public Result<Collection> createCollection(@PathVariable String loginName){
        Collection collection = new Collection();
        collection.setCollectionId(UUID.randomUUID().toString());
        User user = userService.findUserByLoginName(loginName);
        collection.setUserId(user.getUserId());
        collectionService.createCollection(collection);
        return ResultUtil.success(collection);
    }

}
